package com.hongdee.crm.question.controller;

import com.hongdee.common.util.EntityUtils;
import com.hongdee.crm.question.entity.TCrmSurveryQuestion;
import com.hongdee.crm.question.service.ITCrmQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.HashMap;
import java.util.Map;

/**
 * @Name: 问卷管理
 * @Author: Liu XiaoLong
 * @Date: 2017/10/13 10:38
 * @Remark:
 */

@RestController
@RequestMapping("/crm/question")
public class TCrmQuestionController {
    @Autowired
    private ITCrmQuestionService itCrmQuestionService;

    @RequestMapping("/save")
    public Map save(@RequestParam(name = "uid",defaultValue = "") String uid,
                    @RequestParam(name = "token",defaultValue = "") String token,
                    @RequestBody TCrmSurveryQuestion tCrmSurveryQuestion) throws Exception{
        EntityUtils.valid(tCrmSurveryQuestion); // 验证实体
        Map map = new HashMap();
        //TCrmSurveryQuestion rel = itCrmQuestionService.saveOrUpdate(tCrmSurveryQuestion);
        TCrmSurveryQuestion rel = itCrmQuestionService.saveOrUpdate(uid,tCrmSurveryQuestion);
        map.put("data",rel);
        map.put("success",true);
        map.put("msg","保存成功");

        return map;
    }

    @RequestMapping("/page")
    public Map page(@RequestParam(name = "uid",defaultValue = "") String uid,
                    @RequestParam(name = "token",defaultValue = "") String token,
                    @RequestParam(name = "start",defaultValue = "") String start,
                    @RequestParam(name = "limit",defaultValue = "50") String limit,
                    @RequestParam(name = "questionName",defaultValue = "") String questionName) throws Exception{

        Map map = itCrmQuestionService.page(start,limit,questionName);
        //Map map = new HashMap();
        map.put("success",true);
        map.put("msg","查询成功");
        return map;
    }

    /**
     * @Name: 获取问题树
     * @Author: Liu XiaoLong
     * @Date: 2017/10/13 17:07
     * @Remark:
     */
    @RequestMapping("/questionTree")
    public Map questionTree(@RequestParam(name = "uid",defaultValue = "") String uid,
                            @RequestParam(name = "token",defaultValue = "") String token,
                            @RequestParam(name = "companyId",defaultValue = "") String companyId) throws Exception{
        Map map = itCrmQuestionService.questionTree(uid);
        map.put("success",true);
        map.put("msg","查询成功");
        return map;
    }

    /**
     * @Name: 问卷预览
     * @Author: Liu XiaoLong
     * @Date: 2017/10/17 11:20
     * @Remark:
     */
    @RequestMapping("/questionPreview")
    public Map getQuestionPage(@RequestParam(name = "uid",defaultValue = "") String uid,
                               @RequestParam(name = "token",defaultValue = "") String token,
                               @RequestParam(name = "questionId",defaultValue = "") String questionId) throws Exception{
        Map map = itCrmQuestionService.getQuestionPage(uid,questionId);
        map.put("success",true);
        map.put("msg","查询成功");
        return map;
    }

    /**
     * @Name: 删除问卷
     * @Author: Liu XiaoLong
     * @Date: 2017/10/17 14:38
     * @Remark:
     */
    @RequestMapping("/questionDelete")
    public Map questionDelete(@RequestParam(name = "uid",defaultValue = "") String uid,
                               @RequestParam(name = "token",defaultValue = "") String token,
                               @RequestParam(name = "questionId",defaultValue = "") String questionId) throws Exception{
        Map map = itCrmQuestionService.questionDelete(uid,questionId);
        map.put("success",true);
        map.put("msg","删除成功");
        return map;
    }
    /**
     * @Name: 详情查询
     * @Author: Liu XiaoLong
     * @Date: 2017/10/17 17:33
     * @Remark:
     */
    @RequestMapping("/info")
    public Map Info(@RequestParam(name = "uid",defaultValue = "") String uid,
                    @RequestParam(name = "token",defaultValue = "") String token,
                    @RequestParam(name = "id",defaultValue = "") String id) throws Exception{
        Map map = itCrmQuestionService.info(uid,id);
        map.put("success",true);
        map.put("msg","查询成功");
        return map;
    }

    /**
     * @Name: 启用
     * @Author: Liu XiaoLong
     * @Date: 2017/10/17 20:18
     * @Remark:
     */
    @RequestMapping("/start")
    public Map start(@RequestParam(name = "uid",defaultValue = "") String uid,
                    @RequestParam(name = "token",defaultValue = "") String token,
                    @RequestParam(name = "id",defaultValue = "") String id) throws Exception{
        itCrmQuestionService.start(id);
        Map map = new HashMap();
        map.put("success",true);
        map.put("msg","启用成功");
        return map;
    }

    /**
     * @Name: 停用
     * @Author: Liu XiaoLong
     * @Date: 2017/10/17 20:18
     * @Remark:
     */
    @RequestMapping("/stop")
    public Map stop(@RequestParam(name = "uid",defaultValue = "") String uid,
                     @RequestParam(name = "token",defaultValue = "") String token,
                     @RequestParam(name = "id",defaultValue = "") String id) throws Exception{
        itCrmQuestionService.stop(id);
        Map map = new HashMap();
        map.put("success",true);
        map.put("msg","停用成功");
        return map;
    }



}
